package com.example.hblog.module.service.serviceImpl;

import com.example.hblog.module.dao.BlogDao;
import com.example.hblog.module.pojo.Blog;
import com.example.hblog.module.service.BlogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class BlogServiceImpl implements BlogService {

    @Autowired
    private BlogDao blogDao;

    @Override
    public void addBlog(Blog blog) {
        blogDao.addBlog(blog);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Blog> allBlog() {
        return blogDao.allBlog();
    }

    @Override
    public Blog showBlog(String id) {
        return blogDao.showBlog(id);
    }

    @Override
    public PageInfo<Blog> getAllUsersByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);//这行是重点，表示从pageNum页开始，每页pageSize条数据
        List<Blog> list = blogDao.allBlog();
        PageInfo<Blog> pageInfo = new PageInfo<Blog>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<Blog> getSearchPage(int pageNum, int pageSize, String title) {
        PageHelper.startPage(pageNum,pageSize);//这行是重点，表示从pageNum页开始，每页pageSize条数据
        List<Blog> list = blogDao.searchBlog(title);
        PageInfo<Blog> pageInfo = new PageInfo<Blog>(list);
        return pageInfo;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Blog> searchBlog(String title) {
        return blogDao.searchBlog(title);
    }



    @Override
    public void editorBlog(Blog blog) {
        blogDao.editorBlog(blog);
    }

    @Override
    public void deleteBlog(String id) {
        blogDao.deleteBlog(id);
    }


}
